﻿package net.wangit.adm.org;

import net.wangit.adm.role.RoleTreeFactory;
import net.wangit.user.org.Org;
import net.wangit.user.org.OrgFactory;
import net.wangit.util.Checker;
import net.wangit.view.tree.Tree;

public class OrgRoleTreeFactory extends RoleTreeFactory {

	private Org organization;

	public OrgRoleTreeFactory() {
	}

	public Tree createTree(String treeDoamin) throws Exception {
		String oid = OrgRoleUI.getAndSetOrganizationId();
		if (Checker.isEmpty(oid)) {
			return null;
		} else {
			organization = OrgFactory.getOrg(oid);
			Tree tree = super.createTree(treeDoamin);
			tree.setCheckAttribute("disabled");
			return tree;
		}
	}

	protected void setRootAttribute(Tree tree1) {
	}

	protected void setCustomAttribute(Tree tree, String roleId) {
		tree.setCheckValue(roleId);
		if (organization != null && organization.containsRole(roleId))
			tree.setCheckAttribute("checked");
	}

	protected void setName(Tree tree, String roleId, String roleName,
			int privilegeCount) {
		tree.setName((new StringBuilder(String.valueOf(privilegeCount)))
				.append(" ").append(roleName).toString());
	}
}
